#include "BSP_UART.h"
#include "BSP_WiFi.h"

#define BUF_SIZE 256
#define UART1_RX_PIN      	(12)//关联引脚
#define UART1_TX_PIN      	(14)
#define UART1_RTS_PIN  		(UART_PIN_NO_CHANGE)
#define UART1_CTS_PIN  		(UART_PIN_NO_CHANGE)

void UART_Init(void)
{
    uart_config_t uart_config =
    {
        .baud_rate = 115200,//波特率
        .data_bits = UART_DATA_8_BITS,//8位数据
        .parity    = UART_PARITY_DISABLE,//不校验
        .stop_bits = UART_STOP_BITS_1,//1位停止位
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,//禁用流控
        .source_clk = UART_SCLK_APB,//apb时钟源
    };
    uart_driver_install(UART_NUM_1, BUF_SIZE, 0, 0, NULL, 0);//驱动安装
    uart_param_config(UART_NUM_1, &uart_config);//配置参数
    uart_set_pin(UART_NUM_1, UART1_TX_PIN, UART1_RX_PIN, UART1_RTS_PIN, UART1_CTS_PIN);//配置引脚

}

void UART_Task(void*p)
{

    xEventGroupWaitBits(WiFi_EventGroupHandle, WIFI_CONNECT_SUCCESS, pdFALSE, pdFALSE, portMAX_DELAY);
    UART_Init();
    int len;
    uint8_t recvbuf[256] = "hello_word\n";
    while (1)
    {
        //len = uart_read_bytes(UART_NUM_1, recvbuf, BUF_SIZE, 100 / portTICK_PERIOD_MS);//读取数据
		
			uart_write_bytes(UART_NUM_1, (const char *) recvbuf, 12);//返回接收数据
	
    }

}